if(undefined == smartstream){
    var smartstream = (function(){
        var _pageSize = 10,
            _offset = '' ,
            _tlatest = '',
            _latest = false,
            _filter = '0' ,
            _order='0*false',
            _displayStatus = 0,//0:min page; 1:max page; 2:search page, 3:export for community
            _next = true ,
            _prev = true,
            _insertOrder = true,
            _searchOffset = '',
            _searchKeyword = '',
			_loader = '',
            _searchCount = 0;
        var minTmpl = $('#smartstream_rowTmpl').html(),
            maxTmpl = $('#smartstream_maxTmpl').html(),
            minPageTmpl = $('#smartstream_min_view'),
            maxPageTmpl = $('#smartstream_max_view'),
            searchPageTmpl = $('#ss_body_search'),
            searchResultContainer = $('#ss_body_search_result_container'),
            searchResultPageTmpl = $('#ss_body_search_results'),
            trendNewsList = $('#ss_trend_news');

        var orderTimeLable = $('#ss_menubar_time_btn'),
            orderTimeArrowUp = $('#ss_order_time_up'),
            orderTimeArrowDown = $('#ss_order_time_down');

        var type2Icon = {xlsx:'main_documents_o_20_20', xls:'main_documents_o_20_20',tif:'main_documents_t_20_20', tiff:'main_documents_t_20_20', docx:'main_documents_e_20_20', doc:'main_documents_e_20_20', pdf:'main_documents_f_20_20', ppt:'main_big_k_20_20', pptx:'main_big_k_20_20', txt:'main_big_n_20_20', zip:'main_big_m_20_20'};

        var menuItems = [];//filter items

        var window_liked_users;
        var useragent = Workport.getBrowser();
        return{
            init:function(){
                var self = this;
                var height = $(window).height() - 110;
                if(useragent == 'ipad'){
                    $('#smartstream_min_view').css('width','256px');
                    $('#smartstream_min_view').css('height',height);
                    $('#smartstream_max_view').css('width','768px');
                    $('#smartstream_max_view').css('height',height);
                    $('#ss_body_search_results').css('height',height-60);
                    $('#ss_body_search_results').css('width','768px');
                    $('#ss_body_search_results').css('overflow-y','scroll');
                    $("#ss_body_search_results").bind("scroll",function(){
                        if($("#ss_body_search_results")[0].scrollTop == 0){ //top
                            self.doTop();
                        } else if($("#ss_body_search_results")[0].scrollHeight <= $("#ss_body_search_results")[0].scrollTop + $("#ss_body_search_results").height()){ // bottom
                            self.append();
                        }
                    }); 
                } else{
                    minPageTmpl.slimscroll({
                        wheelStep : 20,
                        width : 256,
                        height : height,
                        start : 'top',
                        disableFadeOut:true,
                        touchScrollStep : 200
                    });
                    maxPageTmpl.slimscroll({
                        wheelStep : 20,
                        width : 768,
                        height : height,
                        disableFadeOut:true,
                        start : 'top',
                        touchScrollStep : 200
                    });
                    maxPageTmpl.parent().hide();
                    searchResultPageTmpl.slimscroll({
                        wheelStep : 20,
                        width : 768,
                        height : height-60,
                        start : 'top',
                        disableFadeOut:true,
                        touchScrollStep : 200
                    });
                    searchResultPageTmpl.slimScroll().bind('slimscroll',function(e,pos){
                        if('bottom' ==  pos){
                            self.append();
                        }
                        if('top' == pos){
                            self.doTop();
                        }
                    }); 
                }
                
                searchPageTmpl.hide();
				self._loader = new Workport.Loader($('#smartsteam'),{position:'center',imgCSS:{'margin-top': '0px'},text:'Loading',imgColor:'black',hasMask:false,textCSS:{'color':'black'}});
                self.minTmp();

                //filter
                Workport.StreamAPI.getFilter(function (_d) {
                    Workport.StreamAPI.getEntities(function(_data){
                        var listInnerHTML = '<li data-value="0">Get All</li>';
                        menuItems.push('Filter Posts');
                        for (var i = 0; i < _d.length; i++) {
                            switch (_d[i].FilterName) {
                                case 'Notifications':
                                    var html = '<li data-value="' + 2 + '"><span class="filterMenu_right">' + _d[i].FilterName + '</span><ul>';
                                    for(var j = 0; j < _data.length; j ++) {
                                        var name = 'null';
                                        if (_data[j].EntityName) {
                                            name = _data[j].EntityName;
                                        }
                                        html += '<li data-value="2*'+_data[j].EntityName+'">'+name+'</li>';
                                    }
                                    html += '</ul></li>';
                                    listInnerHTML += html;
                                    break;
								/*
                                case 'Pending Items':
                                    listInnerHTML += '<li data-value="' + 3 + '">' + _d[i].FilterName + '</li>';
                                    break;
                                case 'Following':
                                    listInnerHTML += '<li data-value="' + 4 + '">' + _d[i].FilterName + '</li>';
                                    break;
                                case 'My Posts':
                                    listInnerHTML += '<li data-value="' + 5 + '">' + _d[i].FilterName + '</li>';
                                    break;
                                case 'Bookmark':
                                    listInnerHTML += '<li data-value="' + 6 + '">' + _d[i].FilterName + '</li>';
                                    break;
                                    */
                            }
                            menuItems.push(_d[i].FilterName);
                        }
                        $('#filterMenu_list').html(listInnerHTML);
                        $('#filterMenu').kendoMenu({
                            select: function(e) {
                                if(e.item.getAttribute("data-value") != undefined){
                                    self.onFilterClicked(e);
                                }
                            }
                        });
                    }, {sync : false});
                },{sync : false});
                //windows
                window_liked_users = $('#ss_window_liked_users');
                window_liked_users.kendoWindow({
                    width:384,
                    height:'auto',
                    title:"Liked Users",
                    visible:false,
                    model:true,
                    draggable: false,
                    resizable: false,
                    modal: true,
                    actions:["Close"],
                    close:function(){
                        window_liked_users.html('');
                    }
                });
				
				
            },
            minTmp:function(){
                var self = this;
                _displayStatus = 0;
                _offset = '';
                _next = false;
                _prev = true;
                _tlatest = '';
                _latest = false;
                minPageTmpl.off('*');
                minPageTmpl.empty();
                maxPageTmpl.off('*');
                maxPageTmpl.empty();
                trendNewsList.hide();
                if(useragent != 'ipad'){
                    minPageTmpl.slimScroll().unbind('slimscroll');
                }
				self._loader.setOptions({position:'center',text:'Loading',imgCSS:{'margin-top': '0px'},imgColor:'black',hasMask:false,textCSS:{'color':'black'}});
				self._loader.show();
                Workport.StreamAPI.getBasicStream(function(_data,httpCode){
					self._loader.hide();
					if(getHttpCodeStatus(httpCode)){
						smartstream.showTimeoutMessage('min');
						return;
					}else{
						smartstream.hideTimeoutMessage();
					}
                    if(_data && $.isArray(_data.notification)){
                        self.render(_data.notification,true);
                        if (_data.notification.length) {
                            _offset = _data.notification.pop().LastModifiedDate;
                        }
                        if (_data.notification.length) {
                            _tlatest = _data.notification.shift().LastModifiedDate;
                        } else {
                            _tlatest = _offset;
                        }
                        _next = true;
                    } else {
                        if (_displayStatus == 0 && !_offset && _filter == '0' && _tlatest == '') {
                            $('#smartstream_min_view').html('<div id="smartstream_min_began" style="margin-left: 15px;"><img src="imgs/beganSmartSream.png"></div>');
                            $('#smartstream_min_view').css('margin-top','0px');
                            setTimeout(function(){
                                $('#smartstream_min_began').hide();
                            },2000);

                        } else {
                            //$('#smartstream_min_view').css('margin-top','15px');
							var innerHtml = '<div style="text-align: center;"><span id="smartstream_no_result_min">No results found for the selected filter criteria.</span></div>';
							$('#smartstream_min_view').html(innerHtml);
                        }
                    }
                    if(useragent == 'ipad'){
                        $('#smartstream_min_view').css('overflow-y','scroll');                      
                        $("#smartstream_min_view").bind("scroll",function(){
                            if($("#smartstream_min_view").scrollTop() == 0){ //top
                                self.doTop();
                            } 
                            else if($("#smartstream_min_view")[0].scrollHeight <= $("#smartstream_min_view").scrollTop() + $("#smartstream_min_view").height()){
                              self.append();
                            }
                        });
                    } else{
                        minPageTmpl.slimScroll().bind('slimscroll',function(e,pos){
                            if('bottom' ==  pos){
                                self.append();
                            }
                            if('top' == pos){
                                self.doTop();
                            }
                        });
                    }
                }, {pageSize:_pageSize, offset:_offset, latest:_latest, filter:_filter,sync:false });//true
                orderTimeLable.hide();
            },
            maxTmp:function(){
                var self = this;
                _displayStatus = 1;
                _offset = '';
                _next = false;
                _prev = true;
                _tlatest = '';
                _latest = false;
                maxPageTmpl.off('*');
                maxPageTmpl.empty();
//                trendNewsList.show();
                if(useragent != 'ipad'){
                    maxPageTmpl.slimScroll().unbind('slimscroll');
                }
				maxPageTmpl.show();
				self._loader.reset();
				self._loader.setOptions({position:'center',text:'Loading',imgColor:'black',hasMask:false,textCSS:{'color':'black'}});
				self._loader.show();
                Workport.StreamAPI.getDefaultStream(function(_data,httpCode){
					self._loader.hide();
					if(getHttpCodeStatus(httpCode)){
						smartstream.showTimeoutMessage('max');
						return;
					}else{
						smartstream.hideTimeoutMessage();
					}
                    if(_data && $.isArray(_data.notification)){
                        self.render(_data.notification,true);
                        if (_data.notification.length) {
                            _offset = _data.notification.pop().LastModifiedDate;
                        }
                        if (_data.notification.length) {
                            _tlatest = _data.notification.shift().LastModifiedDate;
                        } else {
                            _tlatest = _offset;
                        }
                        _next = true;
                    } else {
                        if (_displayStatus == 0 && !_offset && _filter == '0' && _tlatest == '') {
                            $('#smartstream_max_view').html('<div id="smartstream_max_began" style="margin-left: 15px;"><img src="imgs/beganSmartSream.png"></div>');
                            $('#smartstream_max_view').css('margin-top','0px');
                        } else {
                            //$('#smartstream_max_view').css('margin-top','15px');
							var innerHtml = '<div style="text-align: center;"><span id="smartstream_no_result_max" >No results found for the selected filter criteria.</span></div>';
							$('#smartstream_max_view').html(innerHtml);
                        }
                    }
                    if(useragent == 'ipad'){
                        $('#smartstream_max_view').css('overflow-y','scroll');  
                        $("#smartstream_max_view").bind("scroll",function(){
                            if($("#smartstream_max_view").scrollTop() == 0){ //top
                                self.doTop();
                            } 
                            else if($("#smartstream_max_view")[0].scrollHeight <= $("#smartstream_max_view").scrollTop() + $("#smartstream_max_view").height()){
                              self.append();
                            }
                        });
                    } else {
                        maxPageTmpl.slimScroll().bind('slimscroll',function(e,pos){
                            if('bottom' ==  pos){
                                self.append();
                            }
                            if('top' == pos){
                                self.doTop();
                            }
                        });
                    }
                },{pageSize:_pageSize,offset:'',latest:false,filter:_filter,order:_order,sync:false});
                orderTimeLable.show();
            },
            zoomin : function () {
                var self = this;
				smartstream.hideTimeoutMessage();
                minPageTmpl.parent().hide();
                searchPageTmpl.hide();
                maxPageTmpl.parent().show(function () {
                     minPageTmpl.hide();
                     minPageTmpl.empty();
                     maxPageTmpl.show();
                    self.maxTmp();
                });
            },
            zoomout : function () {
                var self = this;
				smartstream.hideTimeoutMessage();
                maxPageTmpl.parent().hide();
                minPageTmpl.parent().show(function () {
                    minPageTmpl.show();
                    maxPageTmpl.hide();
                    maxPageTmpl.empty();
                    self.minTmp();
                });

            },
            getAppIcon:function(type){
                var className = 'main_documents_e_20_20';
                if (type2Icon[type]) {
                    className = type2Icon[type];
                }
                return '<i class="'+className+'"></i>';
            },
            doTop:function(){
                if (!_prev) {
                    return;
                }
                var self = this;
                _latest = true;
                _prev = false;
                switch (_displayStatus) {
                    case 0:
						self._loader.setOptions({position:'up',text:'',imgColor:'black',hasMask:false,textCSS:{'color':'black'},imgCSS:{"margin-top":"50px"}});
						self._loader.show();
                        Workport.StreamAPI.getBasicStream(function(_data){
							self._loader.hide();
                            if(_data && $.isArray(_data.notification)){
								_insertOrder = false;
                                self.render(_data.notification);
                                if (_data.notification.length) {
                                    _tlatest = _data.notification.shift().LastModifiedDate;
                                } else {
                                    _tlatest = _offset;
                                }
                            }
                            _prev = true;
                        }, {pageSize:_pageSize, offset:_tlatest, latest:true, filter:_filter,sync:false });//true
                        break;
                    case 1:
						self._loader.setOptions({position:'up',text:'',imgColor:'black',hasMask:false,textCSS:{'color':'black'},imgCSS:{"margin-top":"50px"}});
						self._loader.show();
                        Workport.StreamAPI.getDefaultStream(function(_data){
							self._loader.hide();
                            if(_data && $.isArray(_data.notification)){
								_insertOrder = false;
                                self.render(_data.notification);
                                if (_data.notification.length) {
                                    _tlatest = _data.notification.shift().LastModifiedDate;
                                } else {
                                    _tlatest = _offset;
                                }
                            }
                            _prev = true;
                        },{pageSize:_pageSize,offset:_tlatest,latest:true,filter:_filter,order:_order,sync:false});
                        break;
                    case 2:
                        break;
                    default :
                        break;
                }
            },
            append:function(){
                if (!_next) {
                    return;
                }
                var self = this;
                _latest = false;
                _next =false;
                switch (_displayStatus) {
                    case 0:
						self._loader.setContent($('#smartsteam'), {position:'down',text:'',imgColor:'black',hasMask:false,textCSS:{'color':'black'}});
						self._loader.show();
                        Workport.StreamAPI.getBasicStream(function(_data){
							self._loader.hide();
                            if(_data && $.isArray(_data.notification)){
								 _insertOrder = true;
                                self.render(_data.notification);
                                if (_data.notification.length) {
                                    _offset = _data.notification.pop().LastModifiedDate;
                                }
                                _next = true;
                            }
                        }, {pageSize:_pageSize, offset:_offset, latest:_latest, filter:_filter,sync:false });//true
                        break;
                    case 1:
						self._loader.setOptions({position:'down',text:'',imgColor:'black',hasMask:false,textCSS:{'color':'black'}});
						self._loader.show();
                        Workport.StreamAPI.getDefaultStream(function(_data){
							self._loader.hide();
                            if(_data && $.isArray(_data.notification)){
								 _insertOrder = true;
                                self.render(_data.notification);
                                if (_data.notification.length) {
                                    _offset = _data.notification.pop().LastModifiedDate;
                                }
                                _next = true;
                            }
                        },{pageSize:_pageSize,offset:_offset,latest:false,filter:_filter,order:_order,sync:false});
                        break;
                    case 2:
						self._loader.setOptions({position:'down',text:'',imgColor:'black',hasMask:false,textCSS:{'color':'black'}})
						self._loader.show();
                        var data = {key:_searchKeyword,pageSize:_pageSize,type:"U", offset : _searchOffset,sync:false};
                        Workport.StreamAPI.searchStream(function(_d,_code) {
							self._loader.hide();
                            if(!_d){
                                Workport.utils.alertMsg("", 'network error!', function(_data){});
                                return ;
                            }
                            if(!_d.notification){

                            }else {
                                searchResultContainer.show();
								 _insertOrder = true;
                                self.render(_d.notification);
                                _searchCount += _d.notification.length;
                                _searchOffset = _d.notification.pop().LastModifiedDate;
                                $('#ss_body_search_count').text(' > Showing ' +_searchCount + ' result(s) for ' + _searchKeyword);
                                if (_searchCount == 0) {
                                    searchResultPageTmpl.html('<p style="font-size: 12px; text-align: center;width: 768px;margin-top: 25px;">No results for <span style="color: #ff0000">'+_searchKeyword+'</span>.</p>');
                                }
                                _next = true;
                            }
                        }, data);
                        break;
                    default :
                        break;
                }
            },
            deleteRow:function(obj){
                $('#'+obj.id+',#'+obj.id+'_line').remove();
				$('#global_alert_win').find('span.no').attr("id","smartstream_delete_msg_cancel_button");
				$('#global_alert_win').find('p').attr("id","smartstream_delete_msg");
                Workport.utils.alertMsg("Delete",'Deleting the update will also delete all attachments associated with  the update. Are you sure you want to delete the update?',"Delete",function(_is){
                    if(_is==true){
                        Workport.StreamAPI.deleteStream(function(_d,_c){
                            if(_d) {
                                if (_d.ResponseCode == "WP1008") {
                                    $('#max_' + obj.id).remove();
                                    $('#max_' + obj.id + '_line').remove();
									$('#global_alert_win').find('p').attr("id","smartstream_delete_sucess_msg");
                                    Workport.utils.alertMsg("", "Your update has been deleted successfully.", function (_data) {});
                                } else if (_d.ResponseCode == "WP1007"){
									 Workport.utils.alertMsg("", "The update cannot be deleted. A document associated with this update has been checked out.", function () {});
								}
								else {
                                    Workport.utils.alertMsg("", _d.ResponseMessage, function () {
                                });
                                }
                            }
                        },obj);
                    }
                });
            },
            isliked:function(obj,param){
				var _self = this;
				if(this.isLiked)
					return;
				this.isLiked = true;
                var isLikeMark =  $(obj).attr('status') ;
                isLikeMark = isLikeMark == 'false' ? 'true' :'false';
                param.action = isLikeMark == 'true'? 0 : 1 ;
                Workport.StreamAPI.postLike(function(_d,_c){
					_self.isLiked = false;
                    if(_d.ResponseCode=="WP1008"){
                        $(obj).attr('status',isLikeMark);
                        $(obj).attr('class',isLikeMark == 'true'? 'main_smartstream_t_8_8 smartsteam_clickable':'main_smartstream_w_8_8 smartsteam_clickable');
						var linksCount = $(obj).parent().find('.likesCount')[0];
						if (isLikeMark == 'true'){
							$(obj).attr('title', 'You have Liked this');
							linksCount.innerHTML = parseInt(linksCount.innerHTML)+1;
							$(linksCount).attr('class', 'likesCount smartsteam_clickable');
						}
						else {
							$(obj).attr('title', 'Like this');
							linksCount.innerHTML = parseInt(linksCount.innerHTML)-1;
							if(linksCount.innerHTML == 0)
								$(linksCount).removeClass('smartsteam_clickable');
						}
                    }else{
                        Workport.utils.alertMsg("", _d.ResponseMessage, function(){});
                    }
                },param);
            },
            bookmark:function(obj,param){
                var isBookmark =  $(obj).attr('status') ;
                isBookmark = isBookmark == 'false' ? 'true' :'false';
                param.action = isBookmark == 'true'? 0 : 1 ;
                Workport.StreamAPI.bookmark(function(_d,_c){
                    if(_d.ResponseCode=="WP1008"){
                        $(obj).attr('status',isBookmark);
                        $(obj).attr('class',isBookmark == 'true'? 'main_smartstream_ab_8_8 smartsteam_clickable':'main_smartstream_aa_8_8 smartsteam_clickable');
                        $(obj).attr('title', isBookmark == 'true'? 'Unbookmark':'Bookmark');
                    }else{
                        Workport.utils.alertMsg("", _d.ResponseMessage, function(_data){});
                    }
                },param);
            },
            subscribe:function(obj,param){
                var isSubscribe = $(obj).attr('status') ;
                isSubscribe = isSubscribe == 'false' ? 'true' :'false';
                param.action = isSubscribe == 'true'? 0 : 1 ;
                Workport.StreamAPI.subscriptionMail(function(_d,_c){
                    if(_d.ResponseCode=="WP1008"){
                        $(obj).attr('status',isSubscribe);
                        $(obj).attr('class',isSubscribe == 'true'? 'main_calendar_t_8_8 smartsteam_clickable':'main_calendar_u_8_8 smartsteam_clickable');
                        $(obj).attr('title',isSubscribe == 'true'? 'Stop Mail Alerts':'Receive Mail Alerts');
                    }else{
                        Workport.utils.alertMsg("", _d.ResponseMessage, function(_data){});
                    }
                },param);
            },
            'default':function(obj){
                $(obj).hide();
                $(obj).parent('.pic').css({'background':'url(imgs/img20.png)'});
            },
            setDefaultIcon:function(obj){
                $(obj).attr({'src':'imgs/img20.png'});
            },
            toSingleImg:function(obj){
                $(obj).addClass('ss_single_person_icon');
                $(obj).attr('src','imgs/UserDefault.png');
            },
            toMultiImg:function(obj){
                $(obj).addClass('ss_multi_person_icon');
                $(obj).attr('src','imgs/CommunityDefault.png');
            },
            showDetailWindowWithURL :  function (source,url,notID,notType,tagID,creatDate,notText,commentListPageSize){
                /*var cb = function () {
                    Workport.StreamAPI.getStreamByNotify(function(_d,_code){
                        if(!_d){
                            Workport.utils.alertMsg("", 'network error!', function(_data){});
                            return ;
                        }
                        if(_d.notification==null){
                            Workport.utils.alertMsg("", "Your update has been deleted successfully.", function(_data){});
                            return;
                        }

                        var rowTmpl = _displayStatus ? maxTmpl : minTmpl;
                        var tmp = kendo.template($.trim(rowTmpl),{useWithBlock:false});
                        var arr = new Array();
                        $.map(_d.notification,function(_data){
                            arr.push(tmp(_data));
                        });
                        var prex = ['min_', 'max_', 'max_'];
                        var line = $('#' + prex[_displayStatus] + notID + '_line');
                        line.remove();
                        var body = $('#' + prex[_displayStatus] + notID);
                        body.replaceWith(arr.join(''));
                    },{ notificationId:notID,type: notType, targetId: tagID,sync:false,source:source});//true
                };*/
                show_ss_topic_detail_win_with_iframe(source,url, notID,notType,tagID,creatDate,notText,commentListPageSize,this.updateNotifactionDetail);
            },
            showDetailWindow : function (source,notID,notType,tagID,creatDate,notText,commentListPageSize){
                /*var cb = function () {
                    Workport.StreamAPI.getStreamByNotify(function(_d,_code){
                        if(!_d){
                            Workport.utils.alertMsg("", 'network error!', function(_data){});
                            return ;
                        }
                        if(_d.notification==null){
                            Workport.utils.alertMsg("", "Your update has been deleted successfully.", function(_data){});
                            return;
                        }

                        var rowTmpl = _displayStatus ? maxTmpl : minTmpl;
                        var tmp = kendo.template($.trim(rowTmpl),{useWithBlock:false});
                        var arr = new Array();
                        $.map(_d.notification,function(_data){
                            arr.push(tmp(_data));
                        });
                        var prex = ['min_', 'max_', 'max_'];
                        var line = $('#' + prex[_displayStatus] + notID + '_line');
                        line.remove();
                        var body = $('#' + prex[_displayStatus] + notID);
                        body.replaceWith(arr.join(''));
                    },{ notificationId:notID,type: notType, targetId: tagID,sync:false,source:source});//true
                };*/
                show_ss_topic_detail_win(source,notID,notType,tagID,creatDate,notText,commentListPageSize, this.updateNotifactionDetail);
            },
            updateNotifactionDetail:function(notID,notType,tagID,source){
                Workport.StreamAPI.getStreamByNotify(function(_d,_code){
                    if(!_d){
                        Workport.utils.alertMsg("", 'network error!', function(_data){});
                        return ;
                    }
                    if(_d.notification==null){
                        Workport.utils.alertMsg("", "Your update has been deleted successfully.", function(_data){});
                        return;
                    }

                    var rowTmpl = _displayStatus ? maxTmpl : minTmpl;
                    var tmp = kendo.template($.trim(rowTmpl),{useWithBlock:false});
                    var arr = new Array();
                    $.map(_d.notification,function(_data){
                        arr.push(tmp(_data));
                    });
                    var prex = ['min_', 'max_', 'max_'];
                    var line = $('#' + prex[_displayStatus] + notID + '_line');
                    line.remove();
                    var body = $('#' + prex[_displayStatus] + notID);
                    body.replaceWith(arr.join(''));
					if (_displayStatus == 2) {
						searchResultPageTmpl.find('.ss_title').highlight(_searchKeyword);
						searchResultPageTmpl.find('.ss_entity').highlight(_searchKeyword);
					}
                },{ notificationId:notID,type: notType, targetId: tagID,sync:false,source:source});
            },
            onFilterClicked : function (e) {
                _filter = e.item.getAttribute("data-value");
                var text = $(e.item).find('span')[0].textContent;
                if (text == 'Get All') {
                    text = 'Filter Posts';
                }
                var self = this;
                $('#filterMenu_selected').text(text);
                if (!_displayStatus) {
                    self.minTmp();
                } else {
                    searchPageTmpl.hide();
                    maxPageTmpl.parent().show();
                    self.maxTmp();
                }
            },
            onLickedCountClicked : function (element, notificationId) {
                var count = parseInt(element.innerHTML);
                if (!count || count == 0) {
                    return;
                }
                var likeUsersData={ targetId:notificationId,pageSize: 200, pageNumber: 0};
                Workport.StreamAPI.getLikeByNotify(function(result,_c){
                    if(result){
                        if(result.length > 0 && result[0].LikedUsersDetails){
                            if(result[0].LikedUsersDetails.length > 0){
                                var data=result[0].LikedUsersDetails;
                                var tmlt = kendo.template($('#ss_window_tmpl_liked_users').html(),{useWithBlock:false});
                                var arr = [];
                                $.map(data,function(_data){
                                    arr.push(tmlt(_data));
                                });
                                window_liked_users.html(arr.join(''));
                                arr.length = 0;
                                window_liked_users.data('kendoWindow').center();
                                window_liked_users.data('kendoWindow').open();
                                window_liked_users.prev().find(".k-i-close").attr("id","ss_window_liked_users_close");
                            }
                        }else{
                            Workport.utils.alertMsg("", "LikedUsersDetails is null.", function(_data){});
                        }
                    }else{
                        Workport.utils.alertMsg("", "Liked users list response is Null.", function(_data){});
                    }
                },likeUsersData);
            },
            onShareButtonClicked : function () {
                var self = this;
                var cb = function () {
                    self.doTop();
                };
                smartstreamShareWinFunc.share_win_create(cb);
            },
            onSearchClicked : function () {
                if(useragent == 'ipad'){
                   var minDisplay = minPageTmpl.css('display'); 
                }else{
                   var minDisplay = minPageTmpl.parent().css('display');
                }
                var searchDisplay = searchPageTmpl.css('display');
                if (!minDisplay || minDisplay == 'block') {
                    HomePage_Scrollable.zoom(WPMoudleManager.getModule('smartstream').index);
                } else if (!searchDisplay || searchDisplay == 'block') {
                    this.onBackToAllClicked();
                    return;
                }
                $('#ss_search_keywords_input').val('');
                searchResultPageTmpl.off('*');
                searchResultPageTmpl.empty();
                searchPageTmpl.show();
                searchResultContainer.hide();
                _offset = '';
//                _displayStatus = 2;
                _searchKeyword = '';
                _searchCount = 0;
            },
            onBackToAllClicked : function () {
                searchPageTmpl.hide();
                if(useragent == 'ipad'){
                    maxPageTmpl.show();
                }else{
                    maxPageTmpl.parent().show();
                }
                _displayStatus = 1;
                this.maxTmp();
            },
			onShareEamilClicked : function (title,text) {
				share_email_win.open(title,text);
			},
            doSearch : function () {
                var self = this;
                _next = false;
                var searchBar = $('#ss_search_keywords_input');
                _searchKeyword = searchBar.val();
                /*if($.trim(_searchKeyword) == "") {
                    searchBar.kendoTooltip({
                        content: 'Please input the keywords.',
                        position: "right",
                        showOn: false
                    });
                    searchBar.data('kendoTooltip').show();
                    return;
                }*/
                var searchBar_length = searchBar.kendoTooltip({
                                    content: 'Please input the keywords.',
                                    position: "right",
                                    showOn: false,
                                    show: function() {
                                            isShowUserNameInfo=true;
                                        },
                                    hide: function() {
                                            isShowUserNameInfo=false;
                                        }
                                }).data('kendoTooltip');
				searchBar.on('input',function(e){
                    searchBar_length.hide();
                });
                if($.trim(_searchKeyword) == "") {
                    searchBar_length.show();
					return;
                }
                searchResultPageTmpl.off('*');
                searchResultPageTmpl.empty();
                _searchOffset = '';
                _displayStatus = 2;
                _searchCount = 0;
                var data = {key:$.param({key:_searchKeyword}).substring(4),pageSize:_pageSize,type:"U", offset : _searchOffset,sync:false};
				if(maxPageTmpl.is(":visible")){
					$('#smartstream_max_view').empty();
					$('#smartstream_max_view').html("");
					self._loader.setOptions({imgColor:'black',text:'Loading',position:'center',hasMask:false,textCSS:{'color':'black'}});
				}	
				else {
					searchResultPageTmpl.empty();
					self._loader.setOptions({imgColor:'black',text:'Loading',position:'center',hasMask:false,textCSS:{'color':'black'}});
				}
					
				self._loader.show();
				
                Workport.StreamAPI.searchStream(function(_d,_code) {
					self._loader.hide();
                    if(!_d){
                        Workport.utils.alertMsg("", 'network error!', function(_data){});
                        return ;
                    }
                    if(!_d.notification){
                        searchResultContainer.show();
                        $('#ss_body_search_count').text(' > Showing 0 result(s) for ' + _searchKeyword);
                        if (_searchCount == 0) {
                            searchResultPageTmpl.html('<p style="font-size: 12px; text-align: center;width: 768px;margin-top: 25px;">No results for <span style="color: #ff0000">'+_searchKeyword+'</span>.</p>');
                        }
                    }else {
                        maxPageTmpl.off('*');
                        maxPageTmpl.empty();
                        if(useragent =='ipad'){
                            maxPageTmpl.hide();
                        }else{
                            maxPageTmpl.parent().hide();
                        }
                        searchResultContainer.show();
                        self.render(_d.notification);
                        _searchCount += _d.notification.length;
                        _searchOffset = _d.notification.pop().LastModifiedDate;
                        $('#ss_body_search_count').text(' > Showing ' +_searchCount + ' result(s) for ' + _searchKeyword);
                        if (_searchCount == 0) {
                            searchResultPageTmpl.html('<p style="font-size: 12px; text-align: center;width: 768px;margin-top: 25px;">No results for <span style="color: #ff0000">'+_searchKeyword+'</span>.</p>');
                        }
                        _next = true;
                    }
                }, data);
            },
            onTrendNewsTabClicked : function(element) {
                var clickedKeyword = $(element).text();
                $('#ss_search_keywords_input').val(clickedKeyword);
                searchResultPageTmpl.off('*');
                searchResultPageTmpl.empty();
                searchPageTmpl.show();
                searchResultContainer.show();
                $('#ss_body_search_count').text('');
                this.doSearch();
            },
            onOrderTimeClicked : function () {	
                if (_order == '0*false') {
                    _order = '0*true';
                    orderTimeArrowUp.hide();
                    orderTimeArrowDown.show();
                } else {
                    _order = '0*false';
                    orderTimeArrowDown.hide();
                    orderTimeArrowUp.show();
                }
                searchPageTmpl.hide();
                maxPageTmpl.parent().show();
                this.maxTmp();
            },
			
			onTagsClick: function(tag){
                searchResultPageTmpl.off('*');
                searchResultPageTmpl.empty();
                searchPageTmpl.show();
                searchResultContainer.hide();
                _offset = '';
//                _displayStatus = 2;
                _searchKeyword = '';
                _searchCount = 0;
				$('#ss_search_keywords_input').val(tag);
				smartstream.doSearch();
			},
			
			showTimeoutMessage: function(status){
				if(status =='min'){
					$('#ss_time_out_message').css("margin",'0');
					$('#ss_time_out_message').css("width","225px");
				}else{
					$('#ss_time_out_message').css("margin",'0 150px');
					$('#ss_time_out_message').css("width","445px");
				}
				$('#ss_time_out_message').css("display","block");
				$('#ss_time_out_message').text(WP_TIMEOUT_MESSAGE);
			},
			
			hideTimeoutMessage:function(){
				$('#ss_time_out_message').css("display","none");
			},
			
            render:function(_rowData,flag){
				if(flag){
					$('#smartstream_max_view').html("");
					$('#smartstream_min_view').html("");
				}
                var rowTmpl = _displayStatus ? maxTmpl : minTmpl;
                var tmp = kendo.template($.trim(rowTmpl),{useWithBlock:false});
                var arr = new Array();
                var rowHtml;
                $.map(_rowData,function(_data){
                    arr.push(tmp(_data));
                });
                var bodyArr = ['#smartstream_min_view','#smartstream_max_view','#ss_body_search_results'];
                var body = bodyArr[_displayStatus];
                _insertOrder ? $(arr.join('')).appendTo(body) : $(arr.join('')).prependTo(body);
                arr.length = 0 ;
                var pageArr = [minPageTmpl, maxPageTmpl, searchResultPageTmpl];
                var page = pageArr[_displayStatus];
                if(useragent != 'ipad'){
                    page.slimscroll({});
                }
                if (_displayStatus == 2) {
                    searchResultPageTmpl.find('.ss_title').highlight(_searchKeyword);
                    searchResultPageTmpl.find('.ss_entity').highlight(_searchKeyword);
//                    searchResultPageTmpl.highlight(_searchKeyword);
                }
				
				
				/*
				if (_displayStatus == 1) {
					for(var i = 0; i < _rowData.length; i ++){
						var iframe = $('#smartstream_maxTmpl').find("#max_notificationText_"+_rowData[i].NotificationId), contents = iframe.contents(), ifm = iframe[0];
						if (Workport.getBrowser().indexOf('ie') > -1) {
							contents.find('body').html(iframe.attr('srcdoc'));
						}
					}
                }*/
                bodyArr.length = 0;
                pageArr.length = 0;

                //the first time..no result returned...display a tooptip
                if (_displayStatus == 0 && (!_rowData || _rowData.length == 0) && !_offset && _filter == '0' && _tlatest == '') {
                    $('#smartstream_min_view').html('<div id="ss_topic_began" style="margin-left: 15px;"><img src="imgs/beganSmartSream.png"></div>');
                    $('#smartstream_min_view').css('margin-top','0px');
                } else {
                    //$('#smartstream_min_view').css('margin-top','15px');
                }
            }
        };
    })();
	
}

$(function () {
    $('#smartsteam_panel').appendTo('#smartsteam');

    HomePage_Scrollable.registerZoomCallback(WPMoudleManager.getModule('smartstream').index,
        function () {
            smartstream.zoomin();
            $("#ss_panel_top_resize").toggleClass("main_common_f_11_11 main_common_m_13_13");
            $("#ss_panel_top_resize").attr("title",'Collapse');
        },
        function () {
            smartstream.zoomout();
            $("#ss_panel_top_resize").toggleClass("main_common_f_11_11 main_common_m_13_13");
            $("#ss_panel_top_resize").attr("title",'Expand');
        });
    $('#ss_panel_top_resize').bind( {
        click : function (e) {
            HomePage_Scrollable.zoom(WPMoudleManager.getModule('smartstream').index);
        }
    });
	function smartstreamResize (){
		var height = $(window).height() - 110;
		$('#smartstream_max_view').height(height);
		$('#smartstream_min_view').height(height);
		$('#ss_body_search_results').height(height);
		$('#smartsteam_panel').find('.slimScrollDiv').height(height);
	}
	$(window).resize(smartstreamResize);
    smartstream.init();
});